package icu.qx.pbs.controller;

import java.util.ArrayList;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import icu.qx.pbs.domain.GbsGood;
import icu.qx.pbs.domain.PbsProcedureMaterial;
import icu.qx.pbs.domain.vo.ProcedureMaterial;
import icu.qx.pbs.service.IPbsProcedureMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.pbs.domain.PbsProuteProcedure;
import icu.qx.pbs.service.IPbsProuteProcedureService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工艺路线工序Controller
 *
 * @author yong
 * @date 2024-06-15
 */
@RestController
@RequestMapping("/pbs/pProcecureRoute")
public class PbsProuteProcedureController extends BaseController {
    @Autowired
    private IPbsProuteProcedureService pbsProuteProcedureService;

    /**
     * 查询工艺路线工序列表
     */
    @RequiresPermissions("pbs:procedure:list")
    @GetMapping("/list")
    public R<List<PbsProuteProcedure>> list(PbsProuteProcedure pbsProuteProcedure) {
        List<PbsProuteProcedure> list = pbsProuteProcedureService.selectPbsProuteProcedureList(pbsProuteProcedure);
//        if (list != null && list.size() > 0) {
//            PbsProcedureMaterial pbsProcedureMaterial = new PbsProcedureMaterial();
//            pbsProcedureMaterial.setPmProuteCode(list.get(0).getPpProuteCode());
//
//            List<PbsProcedureMaterial> pbsProcedureMaterials = pbsProcedureMaterialService.selectPbsProcedureMaterialList(pbsProcedureMaterial);
//            pbsProcedureMaterials.forEach(e1 -> {
//                list.forEach(e2 -> {
//                    List<ProcedureMaterial> selectedMaterials = e2.getSelectedMaterial();
//                    if (e1.getProcudureCode().equals(e2.getPpProcedureCode())) {
//                        ProcedureMaterial procedureMaterial = new ProcedureMaterial();
//                        BeanUtils.copyProperties(e1.getGbsGood(), procedureMaterial);
//                        procedureMaterial.setProcudereMNum(e1.getProcudereMNum());
//                        selectedMaterials.add(procedureMaterial);
//                    }
//                });
//            });
//
//            list.forEach(e -> {
//                pbsProcedureMaterial.setProcudureCode(e.getPpProcedureCode());
//
//            });
//        }
        System.err.println("list ");
        list.forEach(e -> System.err.println(e.getSelectedMaterial()));
        return R.ok(list);
    }

    /**
     * 查询工艺路线工序列表
     */
    @RequiresPermissions("pbs:procedure:list")
    @GetMapping("/noGood/list")
    public R<List<PbsProuteProcedure>> noGoodList(PbsProuteProcedure pbsProuteProcedure) {
        List<PbsProuteProcedure> list = pbsProuteProcedureService.selectPbsProuteProcedureList(pbsProuteProcedure);
        return R.ok(list);
    }
}
